using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SysFrame.Message;
using System.Reflection;
using System.Data;
using MySql.Data.MySqlClient;

namespace SysFrame.BP
{
    /// <summary>
    /// system_10方法
    /// </summary>
    public class MySQLsystem_10: Isystem_10
    {

        /// <summary>
        /// 得到system_10实体
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public List<Mssystem_10> Getsystem_10MsByQuery(MsQuery msq)
        {
            List<Mssystem_10> listms=new List<Mssystem_10>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            sb.Append("select system_10.* ");
            sb.Append(" from system_10 ");
            sb.Append(" where 1=1 ").Append(msq.strquery);
            if(msq.strorder != null && msq.strorder != "")
            {
				sb.Append(" order by ").Append(msq.strorder);
            }
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                DataSet ds = DbHelperMySQL.Query(lstCmdText[0].ToString());
               if (ds != null && ds.Tables.Count != 0 && ds.Tables[0].Rows.Count != 0)
                {
                	foreach(DataRow dr in ds.Tables[0].Rows)
                	{
                    	Mssystem_10 ms = new Mssystem_10();
                    	if(dr["System_10_10"].ToString()!=""){ms.System_10_10=int.Parse(dr["System_10_10"].ToString());}
                    	if(dr["System_10_20"]!=null){ms.System_10_20=dr["System_10_20"].ToString();}
                    	if(dr["System_10_30"]!=null){ms.System_10_30=dr["System_10_30"].ToString();}
                    	if(dr["System_10_40"]!=null){ms.System_10_40=dr["System_10_40"].ToString();}
                    	if(dr["System_10_50"]!=null){ms.System_10_50=dr["System_10_50"].ToString();}
                    	if(dr["System_10_60"]!=null){ms.System_10_60=dr["System_10_60"].ToString();}
                    	listms.Add(ms);
                	}
                }
            }
            catch{}
            return listms;
        }

        /// <summary>
        ///  保存system_10信息
        /// </summary>
        /// <param name="ms">实体信息 通过System_10_10进行判断有System_10_10就是update</param>
        /// <returns>消息</returns>
        public MsReturned Savesystem_10(Mssystem_10 ms)
        {
            MsReturned msr = new MsReturned();
            if(ms.System_10_10 !=null && ms.System_10_10.ToString() !="" && ms.System_10_10.ToString() != "0")
            {
            	msr = Upsystem_10(ms);
            }
            else
            {
            	msr = Addsystem_10(ms);
            }
            return msr;
        }

        /// <summary>
        ///  新增system_10信息
        /// </summary>
        /// <param name="ms">实体信息 通过System_10_10进行判断有System_10_10就是update</param>
        /// <returns>消息</returns>
        public MsReturned Addsystem_10(Mssystem_10 ms)
        {
            List<string> lstResult = new List<string>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            MsReturned msr = new MsReturned();
            int newRateId = DataBase.GetMaxId("system_10", "System_10_10");
            sb.Append("insert into system_10 (");
            sb.Append("System_10_10,System_10_20,System_10_30,System_10_40,System_10_50,");
            sb.Append("System_10_60");
            sb.Append(")");
            sb.Append("values ( ");
            sb.Append(newRateId.ToString()).Append(",");
            sb.Append("@System_10_20,@System_10_30,@System_10_40,@System_10_50,");
            sb.Append("@System_10_60)");
            MySqlParameter[] parameters = {
            		new MySqlParameter("@System_10_10", MySqlDbType.Int32,11),
            		new MySqlParameter("@System_10_20", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_10_30", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_10_40", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_10_50", MySqlDbType.VarChar,200),
            		new MySqlParameter("@System_10_60", MySqlDbType.VarChar,200)};
            parameters[0].Value = ms.System_10_10;
            parameters[1].Value = ms.System_10_20;
            parameters[2].Value = ms.System_10_30;
            parameters[3].Value = ms.System_10_40;
            parameters[4].Value = ms.System_10_50;
            parameters[5].Value = ms.System_10_60;
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(lstCmdText[0].ToString(),parameters);
                if (iexe > 0)
                {
                    msr.strMsId = newRateId.ToString();
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            lstCmdText = null;
            sb = null;
            return msr;
        }

        /// <summary>
        ///  更新system_10信息
        /// </summary>
        /// <param name="ms">实体信息 通过System_10_10进行判断有System_10_10就是update</param>
        /// <returns>消息</returns>
        public MsReturned Upsystem_10(Mssystem_10 ms)
        {
            List<string> lstResult = new List<string>();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            MsReturned msr = new MsReturned();
           	sb.Append("update system_10 set ");
           	sb.Append(" System_10_10='").Append(ms.System_10_10).Append("' ");// System_10_10 
           	if (ms.System_10_20 !=null && ms.System_10_20.ToString() != ""){
           	    sb.Append(",").Append(" System_10_20='").Append(ms.System_10_20).Append("' ");// System_10_20 
           	}
           	if (ms.System_10_30 !=null && ms.System_10_30.ToString() != ""){
           	    sb.Append(",").Append(" System_10_30='").Append(ms.System_10_30).Append("' ");// System_10_30 
           	}
           	if (ms.System_10_40 !=null && ms.System_10_40.ToString() != ""){
           	    sb.Append(",").Append(" System_10_40='").Append(ms.System_10_40).Append("' ");// System_10_40 
           	}
           	if (ms.System_10_50 !=null && ms.System_10_50.ToString() != ""){
           	    sb.Append(",").Append(" System_10_50='").Append(ms.System_10_50).Append("' ");// System_10_50 
           	}
           	if (ms.System_10_60 !=null && ms.System_10_60.ToString() != ""){
           	    sb.Append(",").Append(" System_10_60='").Append(ms.System_10_60).Append("' ");// System_10_60 
           	}
           	sb.Append(" where System_10_10='").Append(ms.System_10_10).Append("'");// System_10_10 
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(lstCmdText[0].ToString());
                if (iexe > 0)
                {
                    msr.strMsId = ms.System_10_10.ToString();
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            lstCmdText = null;
            sb = null;
            return msr;
        }

        /// <summary>
        /// 得到数据类型
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns>数据类型</returns>
        public MsReturned Getsystem_10ByQuery(MsQuery msq)
        {
        	DataSet ds = null;
        	MsReturned msr = new MsReturned();
            StringBuilder sb = new StringBuilder();
            List<string> lstCmdText = new List<string>();
            sb.Append("select system_10.* ");
            sb.Append(" from system_10 ");
            sb.Append(" where 1=1 ").Append(msq.strquery);
            if(msq.strorder!=null && msq.strorder != "")
            {
				sb.Append(" order by ").Append(msq.strorder);
            }
            lstCmdText.Add(sb.ToString());
            sb.Remove(0, sb.ToString().Length);
            try
            {
                ds = DbHelperMySQL.Query(lstCmdText[0].ToString());
            }
            catch{}
            msr.data = ds;
            return msr;
        }

        /// <summary>
        /// 删除system_10
        /// </summary>
        /// <param name="msq">条件</param>
        /// <returns></returns>
        public MsReturned Deletesystem_10ByQuery(MsQuery msq)
        {
            StringBuilder sb = new StringBuilder();
            MsReturned msr = new MsReturned();
            sb.Append(" delete from system_10 where System_10_10 > 0 ").Append(msq.strquery);
            try
            {
                int iexe = DbHelperMySQL.ExecuteSql(sb.ToString());
                if (iexe > 0)
                {
                    msr.strMsId = "1";
                    msr.strMS = "保存成功!";
                }
                else
                {
                    msr.strMsId = "-1";
                    msr.strMS = "操作失败:服务器忙,请稍后再试!";
                }
            }
            catch
            {
                msr.strMsId = "-1";
                msr.strMS = "操作失败:服务器忙,请稍后再试!";
            }
            sb = null;
            return msr;
        }

    }
}
